// SPDX-License-Identifier: GPL-2.0
/*
 * OOM: TRIGGER USERSPACE
 *
 * (C) 2024.05.01 BuddyZhang1 <buddy.zhang@aliyun.com>
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>

#define MAP_VADDR	0x600000000
#define MAP_SIZE	0x1000

int main()
{
	void *mem;

	/* ALLOC MEMORY */
	while (1) {
		mem = mmap((void *)MAP_VADDR, MAP_SIZE,
			   PROT_READ | PROT_WRITE,
			   MAP_ANONYMOUS | MAP_PRIVATE |
			   MAP_POPULATE,
			   -1,
			   0);
		if (mem == MAP_FAILED) { /* TRIGGER OOM */
			printf("ERROR: ALLOC MEMORY FAILED.\n");
			return -1;
		}
	}

	return 0;
}
